$(document)
		.ready(
				function() {
					var id = getQueryString('id');
					console.log(id);

					$
							.ajax({
								type : "post",
								url : "busOne",
								async : true,
								data : {
									"id" : id
								},
								dataType : 'json',
								success : function(data) {
									console.log(data)
									var articlePath = 'myAssets//img//article//';// 文章文件路径
									var facePath = 'myAssets//img//face//';// 头像文件路径
									var id = data.article.id;// 文章id
									var type = data.article.type;// 类型
									var title = data.article.title;// 标题
									var content = data.article.content;// 内容
									var date = data.article.date;// 发布时间
									var startDate = data.article.startDate;// 活动开始时间
					
									var address = data.article.address;// 地址
									var joinUserNum = data.article.joinUserNum;// 参加人数int

		




									var myFiles = data.article.myFiles;// 文件
									for (var i = 0; i < myFiles.length; i++) {
										var myFilesname = myFiles[i].name;
										// $('#myfile').innerHTML('<img
										// src="'+servicePath+myFilesname+'">');
										$("#myfile").append(
												'<img src="' + articlePath
														+ myFilesname + '">');
										// alert(myFilesname);
									}

									if (type == 'bus') {
										$("#type").html('分类：巴士');
									}
									var newdate = date.substring(0, 10);// 截取出发布日期

									$("#title").html('<h1>'+title+'</h1>');// 标题
									$("#address").html('接车地址：' + address);
									$("#content").html(content);// 内容
									$("#date").html('发表于：' + newdate);// 发布时间
									

									var newstartDate = startDate.substring(10,
											5).replace("-", "月")
											+ '日';// 报名开放日期
								
									var newstartDateSSS = startDate.slice(11);
							
									// 20:30
									console.log('截取后的格式' + newstartDate)
									console.log('截取后的格式' + newstartDateSSS)
									
									$("#startDate").html(newstartDate+" "+newstartDateSSS);
									
									$("#user-name")
											.html(data.article.user.name);
									$("#user-myfile")
											.html('<a href=heUser?id='+data.article.user.id+'> <img src="'+ facePath+ data.article.user.myFile.name+ '" alt=""></a>');// 参加开放时间
									if (data.article.user.phoneNum == null
											|| data.article.user.phoneNum == '') {
										$("#user-phoneNum")
												.html(
														'联系电话：<a href="tel:xxx-xxxxx-xxx">xxx-xxxxx-xxx</a>');// 联系电话
									} else {
										$("#user-phoneNum")
												.html(
														'联系电话：<a href="tel:'
																+ data.article.user.phoneNum
																+ '">'
																+ data.article.user.phoneNum
																+ '</a>');// 联系电话
									}

								
//									$('#join-but')
//									.html('<button type="button" id="doc-prompt-toggle"	class="am-btn am-btn-default  pet_zlnr_user_list1 "	style="background-color: #4DB14D; border-radius: 1000px; font: '+'黑体'+'; font-size: 18px; color: #FEFFFF;">预约位置('+data.article.price+'￥)</button>');
									$('#bus-price')
									.html('购票价格 '+data.article.price+'元');
						
									var joinUser= data.article.joinUser;
									for (var i = 0; i < joinUser.length; i++) {
										if (joinUser[i].id == data.userid) {
											$('#join-but')
													.html(
															'<button type="button"   class="am-btn am-btn-default  pet_zlnr_user_list1 "  style="background-color: #a5a5a5; border-radius :1000px; font: "黑体"; font-size: 18px; color: #FEFFFF;">已预约</button>');
										}
									}
							
								
									

								},
								error : function() {
								}
							});

				})

// 获取url中的参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); // 匹配目标参数
	var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
	if (result != null) {
		return decodeURIComponent(result[2]);
	} else {
		return null;
	}
}

$(function() {
	$('#doc-prompt-toggle').on('click', function() {
		$('#my-prompt').modal({
			relatedTarget : this,
			onConfirm : function(e) {
				var id = getQueryString('id');
				$.ajax({
					type : "post",
					url : "busJoinAdd",
					async : true,
					data : {
						'id' : id,
					},
					dataType : 'json',
					success : function(data) {
						console.log(data)
						var result = data.resultJson;
						if (result == '1') {
							$('#join-but')
							.html(
									'<button type="button"   class="am-btn am-btn-default  pet_zlnr_user_list1 "  style="background-color: #a5a5a5; border-radius :1000px; font: "黑体"; font-size: 18px; color: #FEFFFF;">已预约成功</button>');
						} else {

						}
					},
					error : function() {
					}
				});
			},
			onCancel : function(e) {

			}
		});
	});
})



